 // author : georgeyucjr
# include <bits/stdc++.h>
using ll = long long; using ull = unsigned long long; using i128 = __int128; using u128 = unsigned __int128; 
using arr3 = std ::array<int, 3>; using arr4 = std ::array<int, 4>; using pii = std ::pair<int, int>;
# define ALL(vc) std ::begin(vc), std ::end(vc)
# define forall(x, f) std::for_each(std::begin(x), std::end(x), f)
# define rep(i, f, t, ...) for (std ::decay<decltype(f + t)>::type i = f, _END_##i = t, ##__VA_ARGS__; i <= _END_##i; ++i)
# define per(i, f, t, ...) for (std ::decay<decltype(f + t)>::type i = f, _END_##i = t, ##__VA_ARGS__; i >= _END_##i; --i)
# define rep0(i, f, t, ...) for (std ::decay<decltype(f + t)>::type i = f, _END_##i = t - 1, ##__VA_ARGS__; i <= _END_##i; ++i)
# define per0(i, f, t, ...) for (std ::decay<decltype(f + t)>::type i = f - 1, _END_##i = t, ##__VA_ARGS__; i >= _END_##i; --i)
# define For(i, f, t, s, ...) for (std ::decay<decltype(f + t)>::type i = f, _END_##i = t, ##__VA_ARGS__; i <= _END_##i; i += s)
# define ForD(i, f, t, s, ...) for (std ::decay<decltype(f + t)>::type i = f, _END_##i = t, ##__VA_ARGS__; i >= _END_##i; i -= s)
# define For0(i, f, t, s, ...) for (std ::decay<decltype(f + t)>::type i = f, _END_##i = t - 1, ##__VA_ARGS__; i <= _END_##i; i += s)
# define For0D(i, f, t, s, ...) for (std ::decay<decltype(f + t)>::type i = f - 1, _END_##i = t, ##__VA_ARGS__; i >= _END_##i; i -= s)
# define eb emplace_back
# define pb push_back
# define mkp make_pair
# define FILEIO(filename) freopen(filename ".in", "r", stdin), freopen(filename ".out", "w", stdout)
template <class T> constexpr static T inf = std ::numeric_limits<T>::max() >> 1;
template <class T> inline int SZ(T &&x) { return x.size(); } template <typename T> inline T Abs(const T &x) { return x < 0 ? -x : x; } 
template <typename T> inline T sqr(const T &x) { return x * x; } template <typename T> inline T cbr(const T &x) { return x * x * x; }
template <typename T> inline T Max(const T &x) { return x; } template <typename T> inline T Min(const T &x) { return x; }
template <typename T, typename U, typename... Args> inline T Max(const T &x, const U &y, const Args &...args) { return x < y ? Max(y, args...) : Max(x, args...); }
template <typename T, typename U, typename... Args> inline T Min(const T &x, const U &y, const Args &...args) { return x < y ? Min(x, args...) : Min(y, args...); }
template <typename T, typename... Args> inline void chkmax(T &d, const Args &...x) { d = Max(d, x...); }
template <typename T, typename... Args> inline void chkmin(T &d, const Args &...x) { d = Min(d, x...); } 
using namespace std;

# ifdef georgeyucjr
# include <georgeyucjr/debug.h>
# else
# define dbg(...) 36
# endif

namespace SlowIO {
# ifndef LOCAL
  constexpr std::size_t BUFSIZE = 1 << 20; char ibuf[BUFSIZE], *iS, *iT;
  # define getchar() (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, BUFSIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
# endif
  inline void read(char &c) { c = getchar(); } inline void read(string &str, bool is_move = false) { if (is_move) str += ' '; char c = getchar(); while (c != ' ' && c != '\n') str += c, c = getchar(); }
  template <typename T> inline void read(T &x, bool is_unsigned = false) { x = 0; char ch = getchar(); if (is_unsigned) { while (ch < '0' || ch > '9') ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar ( ); } else { T _read_flag = (T)(1); while (ch < '0' || ch > '9') _read_flag = ch == '-' ? -1 : 1, ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar ( ); x *= _read_flag; } return void(); }
  template <typename T> inline void read(vector<T> &v) { for (T &i : v) read(v); } template <typename T, typename... Args> inline void read(T &x, Args&... args) { read(x), read(args...); } template <typename T, typename U> inline void read(pair<T, U> &p) { read(p.first, p.second); }
  template <typename T, typename U, typename V> inline void read(tuple<T, U, V> &t) { read(get<0>(t), get<1>(t), get<2>(t)); }
# ifndef LOCAL
  char obuf[BUFSIZE], *oS = obuf, *oT = oS + BUFSIZE - 1; inline void flush() { fwrite(obuf, 1, oS - obuf, stdout), oS = obuf; } 
# define putchar(x) (*oS++ = x, ( oS == oT ) ? flush() : void())
# else
# define flush() 36
# endif
  inline void write ( char c ) { putchar ( c ); }  inline void write ( string s ) { for (char c : s) putchar ( c ); }
  template <typename T> inline void write(T x, bool is_unsigned = false) { if (!is_unsigned) if (x < 0) x = -x, putchar ('-'); if (x > 9) write(x / 10); putchar (x % 10 ^ '0'); }
  template <typename T> inline void writeln(T x) { write (x), putchar('\n'); } 
  template <typename T> inline void writespc(T x) { write (x), putchar(' '); }
  template <typename T, typename ... Args> inline void write(T x, Args ... args) { write(x), write(args...); }
  template <typename T, typename ... Args> inline void writeln(T x, Args ... args) { write(x), putchar(' '), write(args...), putchar('\n'); }
  template <typename T, typename ... Args> inline void writespc(T x, Args ... args) { write(x), putchar(' '), write(args...), putchar(' '); }
  template <typename T> inline void writeall(T x, char blank = ' ', bool Endl = true) { std::for_each(std::begin(x), std::end(x), [&](auto x) { write(x), putchar(' '); }); if (Endl) putchar('\n'); }
  inline void writeln() { putchar('\n'); } inline void writespc() { putchar(' '); }
  inline void __attribute__((destructor)) _d() { flush(); return void(); }
} // namespace SlowIO
using namespace SlowIO;

# define int long long

// n * log^2 n

constexpr int N = 4e5 + 5;

int n, q, a[N], len, rt, dstot = 0;
vector<int> dc;
set<int> isv;

# define lson seg[index].ls
# define rson seg[index].rs
# define lc(index) seg[index].ls
# define rc(index) seg[index].rs

struct Node {
	int pre, suf, sm, cnt;
	int ls, rs;
	// void o() {
		// cerr << "pre = " << pre << ", suf = " << suf << ", sm = " << sm << ", cnt = " << cnt << "\n";
	// }
} seg[N << 2];

void pushup(int index) {
	seg[index].pre = seg[lson].pre + seg[rson].pre + seg[rson].cnt * seg[lson].sm;
	seg[index].suf = seg[lson].suf + seg[rson].suf + seg[lson].cnt * seg[rson].sm;
	seg[index].sm  = seg[lson].sm  + seg[rson].sm ;
	seg[index].cnt = seg[lson].cnt + seg[rson].cnt;
}

void upd1(int &index, int l, int r, int qpos, int v) {
	if (!index) index = ++dstot;
	if (l == r) {
		if (v == 1) {
			seg[index].pre = seg[index].suf = seg[index].sm = dc[l - 1], seg[index].cnt = 1;
		} else {
			assert(v == -1);
			seg[index].pre = seg[index].suf = seg[index].sm = seg[index].cnt = 0;
		}
		return ;
	}
	int mid = (l + r) >> 1;
	if (qpos <= mid) upd1(lson, l, mid, qpos, v);
	else upd1(rson, mid + 1, r, qpos, v);
	pushup(index);
}

pair<int, int> Kth(int index, int l, int r, int K, int o) { // o = 0 : kth small; o = 1 : kth big
	if (l == r) {
		return mkp(seg[index].sm, l);
	}
	int mid = (l + r) >> 1;
	if (o == 0) {
		if (seg[lson].cnt >= K) return Kth(lson, l, mid, K, o);
		else {
			auto tans = Kth(rson, mid + 1, r, K - seg[lson].cnt, o);
			return mkp(tans.first + seg[lson].sm, tans.second);
		}
	} else {
		assert(o == 1);
		if (seg[rson].cnt >= K) return Kth(rson, mid + 1, r, K, o);
		else {
			auto tans = Kth(lson, l, mid, K - seg[rson].cnt, o);
			return mkp(seg[rson].sm + tans.first, tans.second);
		}
	}
}

vector<Node> stk;

void get_segnode(int index, int l, int r, int ql, int qr) { // 提取出来，方便操作!!!!!
	if (!index || ql > qr) return ;
	if (l == ql && r == qr) return stk.eb(seg[index]), void();
	int mid = (l + r) >> 1;
	if (qr <= mid) get_segnode(lson, l, mid, ql, qr);
	else if (ql > mid) get_segnode(rson, mid + 1, r, ql, qr);
	else get_segnode(lson, l, mid, ql, mid), get_segnode(rson, mid + 1, r, mid + 1, qr);
}

int rgsm(int l,int r) {
	vector<Node>().swap(stk);
	get_segnode(rt, 1, len, l, r);
	int sm = 0;
	for (auto _ : stk) sm += _.sm;
	return sm;
}

int rgpf(int l, int r, int o) {
	vector<Node>().swap(stk);
	get_segnode(rt, 1, len, l, r);
	ll cs = 0, ret = 0;
	// for (auto _ : stk) _.o();
	if (o == 0) {
		// for (auto _ : stk) ret += _.pre + cs * _.cnt, cs += _.sm;	
		rep(i, 0, SZ(stk) - 1) ret += stk[i].pre + cs * stk[i].cnt, cs += stk[i].sm;
	} else {
		assert(o == 1);
		// reverse(ALL(stk));
		// for (auto _ : stk) ret += _.suf * cs * _.cnt, cs += _.sm;
		per(i, SZ(stk) - 1, 0) ret += stk[i].suf + cs * stk[i].cnt, cs += stk[i].sm;
	}
	return ret;
}

int qry() {
	if (!n) return 0;
	int pl = 0, pr = 0, ans = 0;
	{
		int l = 1, r = n - 1;
		while(l <= r) {
			int mid = (l + r) >> 1;
			ll ansl = Kth(rt, 1, len, mid, 1).first, ansr = Kth(rt, 1, len, mid + 1, 0).first;
			if (ansl >= ansr) pl = mid, r = mid - 1;
			else l = mid + 1;
		}
	}
	{
		int l = 1, r = n - 1;
		while(l <= r) {
			int mid = (l + r) >> 1;
			ll ansl = Kth(rt, 1, len, mid, 1).first, ansr = Kth(rt, 1, len, mid + 1, 0).first;
			if (ansl >= ansr) pr = mid + 1, l = mid + 1;
			else r = mid - 1;
		}
	}
	if (pl == 0) return rgpf(1, len, 1) - rgpf(1, len, 0);
	if (pr < n) {
		int ansl = Kth(rt, 1, len, pr + 1, 0).second, ansr = Kth(rt, 1, len, pr + 1, 1).second;
		ans += rgpf(1, ansr - 1, 1) + rgsm(ansr, len) * (n - pr);
		ans -= rgsm(1, ansl) * (n - pr) + rgpf(ansl + 1, len, 0);
	}
	if (pl > 1) {
		int ansl = Kth(rt, 1, len, pl - 1, 0).second, ansr = Kth(rt, 1, len, pl - 1, 1).second;
		ans += rgpf(ansr, len, 1) - rgpf(1, ansl, 0);
	}
	ans -= rgsm(1, Kth(rt, 1, len, pl, 0).second);
	ans += rgsm(Kth(rt, 1, len, pr, 1).second, len);
	return ans;
}

signed main() {
  FILEIO("kte");
  read(q);
  rep(i, 1, q) 
  	read(a[i]), dc.eb(a[i]);
  sort(ALL(dc)), dc.erase(unique(ALL(dc)), end(dc));
 	rep(i, 1, q) a[i] = lower_bound(ALL(dc), a[i]) - begin(dc) + 1;
 	len = SZ(dc);
 	rep(i, 1, q) {
 		if (!isv.count(a[i])) upd1(rt, 1, len, a[i], 1), isv.emplace(a[i]), ++n;
 		else upd1(rt, 1, len, a[i], -1), isv.erase(a[i]), --n, assert(n >= 0);
 		cout << qry() << "\n";
 	}

# if defined(LOCAL) && !defined(CPH)
  std::cerr << "Spend Time : " << clock() * 1. / CLOCKS_PER_SEC * 1e3 << " ms \n";
# endif
  return 0;
}